package com.huadao.cart_ccs.modle;

import com.huadao.cart_ccs.base.BaseModel;
import com.huadao.cart_ccs.data.bo.LogInfo;
import com.huadao.cart_ccs.greendao.GreenDaoManager;
import com.huadao.cart_ccs.greendao.gen.LogInfoDao;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.Date;
import java.util.List;

public class LogModle extends BaseModel {

    private LogInfoDao logInfoDao;

    public LogModle() {
        logInfoDao =  GreenDaoManager.getInstance().getNoCacheSession().getLogInfoDao();
    }

    public List<LogInfo> getLogInfo(String device){
        QueryBuilder queryBuilder=logInfoDao.queryBuilder();
        if(device!=null){
            queryBuilder.where(LogInfoDao.Properties.Device.eq(device));
        }
        return queryBuilder.orderDesc(LogInfoDao.Properties.Date).limit(20).list();
    }

    public List<LogInfo> getMoreLogInfo(int offset,int limite,String device){
        QueryBuilder queryBuilder=logInfoDao.queryBuilder();
        if(device!=null){
            queryBuilder.where(LogInfoDao.Properties.Device.eq(device));
        }
        return queryBuilder.orderDesc(LogInfoDao.Properties.Date).offset(offset).limit(limite).list();
    }

    public void recordOperation(String device,String operate){
        LogInfo logInfo=new LogInfo();
        logInfo.setDate(new Date());
        logInfo.setDevice(device);
        logInfo.setOperate(operate);
        logInfoDao.insert(logInfo);
    }

//    public void recordOperation(Protocol protocol){
//        protocolDao.insert(protocol);
//    }
}
